/**
 * Copyright ©2012-2018 HopeHaiyang Corporation, All Rights Reserved
 * http://www.wuhanhope.com
 */
package hope.platform.data.web;

import hope.platform.data.domain.User;
import hope.platform.data.server.data.header.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * class info
 *
 * @author hujia
 *         Create at 2018/7/17 10:12
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping(method = RequestMethod.POST)
    public User addUser(@RequestBody User user) throws Exception {
        return userService.addUser(user);
    }

    @RequestMapping(value = "/email/{email}", method = RequestMethod.GET)
    public User getByEmail(@PathVariable String email) throws Exception {
        return userService.getByEmail(email).get();
    }

    @RequestMapping(value = "/email/password/{email}/{password}", method = RequestMethod.GET)
    public User getByEmailAndPassword(@PathVariable String email, @PathVariable String password) throws Exception {
        return userService.getByEmailAndPassword(email, password);
    }

    @RequestMapping(method = RequestMethod.PUT)
    public User UpdateUser(@RequestBody User user) throws Exception {
        return userService.updateUser(user);
    }

    @RequestMapping(value = "/all", method = RequestMethod.GET)
    public List<User> getAll() throws Exception {
        return userService.getAll();
    }
}
